package com.application.chiettinhdienluc.data;

import android.R;
import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferencesData
{
	public final static String APP_NAME_PREF = "ChietTinhPre";
	
	public static int getPreferenceIntValue(Context context, String name_pref, String key, int defValue)
	{		
		int value = defValue;
		SharedPreferences myPrefs = context.getSharedPreferences(name_pref, Context.MODE_PRIVATE);
		value = myPrefs.getInt(key, defValue);
		return value;
	}

	public static long getPreferenceLongValue(Context context, String name_pref, String key, long defValue)
	{		
		long value = defValue;
		SharedPreferences myPrefs = context.getSharedPreferences(name_pref, Context.MODE_PRIVATE);
		value = myPrefs.getLong(key, defValue);
		return value;
	}

	public static boolean getPreferenceBooleanValue(Context context, String name_pref, String key, boolean defValue)
	{
		boolean value = defValue;
		SharedPreferences myPrefs = context.getSharedPreferences(name_pref, Context.MODE_PRIVATE);
		value = myPrefs.getBoolean(key, defValue);
		return value;
	}

	public static String getPreferenceStringValue(Context context, String name_pref, String key, String defValue)
	{		
		String value = defValue;
		SharedPreferences myPrefs = context.getSharedPreferences(name_pref, Context.MODE_PRIVATE);
		value = myPrefs.getString(key, defValue);
		return value;
	}


	public static void setPreferenceIntValue(Context context, String name_pref, final String key, final int value)
	{
		SharedPreferences myPrefs = context.getSharedPreferences(name_pref, Context.MODE_PRIVATE);
		SharedPreferences.Editor prefsEditor = myPrefs.edit();
		prefsEditor.putInt(key, value);
		prefsEditor.commit();
	}

	public static void setPreferenceLongValue(Context context, String name_pref, final String key, final long value)
	{
		SharedPreferences myPrefs = context.getSharedPreferences(name_pref, Context.MODE_PRIVATE);
		SharedPreferences.Editor prefsEditor = myPrefs.edit();
		prefsEditor.putLong(key, value);
		prefsEditor.commit();
	}

	public static void setPreferenceBooleanValue(Context context, String name_pref, final String key, final boolean value)
	{
		SharedPreferences myPrefs = context.getSharedPreferences(name_pref, Context.MODE_PRIVATE);
		SharedPreferences.Editor prefsEditor = myPrefs.edit();
		prefsEditor.putBoolean(key, value);
		prefsEditor.commit();
	}	

	public static void setPreferenceStringValue(Context context, String name_pref, final String key, final String value)
	{
		SharedPreferences myPrefs = context.getSharedPreferences(name_pref, Context.MODE_PRIVATE);
		SharedPreferences.Editor prefsEditor = myPrefs.edit();
		prefsEditor.putString(key, value);
		prefsEditor.commit();
	}
	
	
	public final static String STR_MA_DON_VI_QUAN_LY = "MaDonViQuanLy";	
	public static void setMaDonViQuanLy(Context context, String value)
	{
		setPreferenceStringValue(context, APP_NAME_PREF, STR_MA_DON_VI_QUAN_LY, value);
	}
	public static String getMaDonViQuanLy(Context context)
	{
		return getPreferenceStringValue(context, APP_NAME_PREF, STR_MA_DON_VI_QUAN_LY, "");		
	}
	
	
	public final static String STR_LOCAL_SERVER_IP = "local_ip";	
	public static void setLocalServerIp(Context context, String value)
	{
		setPreferenceStringValue(context, APP_NAME_PREF, STR_LOCAL_SERVER_IP, value);
	}
	public static String getLocalServerIp(Context context)
	{
		return getPreferenceStringValue(context, APP_NAME_PREF, STR_LOCAL_SERVER_IP, "");		
	}
	
	public final static String STR_INTERNET_SERVER_IP = "internet_ip";	
	public static void setInternetServerIp(Context context, String value)
	{
		setPreferenceStringValue(context, APP_NAME_PREF, STR_INTERNET_SERVER_IP, value);
	}
	public static String getInternetServerIp(Context context)
	{
		return getPreferenceStringValue(context, APP_NAME_PREF, STR_INTERNET_SERVER_IP, "");		
	}
		
	
	
	public final static String STR_SERVICE_PORT = "service_port";	
	public static void setServicePort(Context context, String value)
	{
		setPreferenceStringValue(context, APP_NAME_PREF, STR_SERVICE_PORT, value);
	}
	public static String getServicePort(Context context)
	{
		return getPreferenceStringValue(context, APP_NAME_PREF, STR_SERVICE_PORT, "");		
	}
	
}


